﻿using System;
using TallyMarks.Models;


namespace TallyMarks.Calculators
{
    public class LayoutCalculator
    {
        private const int Max = 80;

        public LayoutMath GetLayout(int count)
        {
            var numberOfControlsNeeded = GetNumberOfControlsNeeded(count);
            return new LayoutMath()
                       {
                           NumberofControlsNeeded = numberOfControlsNeeded,
                           NumberOfMarksToRemoveFromLastControl = GetNumberToChop(numberOfControlsNeeded),
                           SizeFactor = GetSizeFactor(count),
                           ScreenFull = count >= Max
                       };
        }

        private static double GetSizeFactor(int count)
        {
            if (count <= 5) return 1;
            if (count <= 20) return 0.5;
            if (count <= Max) return 0.24;
            return 0.20;
        }

        private static double GetNumberToChop(double numberOfControlsNeeded)
        {
            return (Convert.ToInt32(numberOfControlsNeeded) - 1) * 5;
        }

        private static double GetNumberOfControlsNeeded(double count)
        {
            return Math.Ceiling(count / 5);
        }
    }
}
